/*
 * NetHeaderUtil.h
 *
 *  Created on: 2018年7月7日
 *      Author: zhengboyuan
 */

#ifndef NETHEADERUTIL_H_
#define NETHEADERUTIL_H_

#include "BasicType.h"
#include "NetHeader.h"
#include <string>
#include "Socket.h"


class NetHeaderUtil
{
public:
    enum Host
    {
        kNone = 0,
        kSrc = 1,
        kDst
    };

    enum Protocol
    {
        kUnknown = 0,
        kTcp = IP_PROTOCOL_TCP,
        kUdp = IP_PROTOCOL_UDP
    };

public:
    NetHeaderUtil();
    virtual ~NetHeaderUtil();

    static bool isIP(const uint8_t* data, int size);

    static bool isTcpUdp(const uint8_t* data, int size);

    static Protocol getProtocol(const uint8_t* data, int size);

    static const ip_hdr* getIpHdr(const uint8_t* data, int size);
    static const tcp_hdr* getTcpHdr(const uint8_t* data, int size);
    static const udp_hdr* getUdpHdr(const uint8_t* data, int size);

    static Host matchHost(const ip_hdr* ip, const tcp_hdr* hdr, struct sockaddr_in addr);
    static Host matchHost(const ip_hdr* ip, const udp_hdr* hdr, struct sockaddr_in addr);

	static Host matchHostPort(const tcp_hdr* hdr, uint16_t port);
	static Host matchHostPort(const udp_hdr* hdr, uint16_t port);

	static Host matchHostIP(const ip_hdr* hdr, uint32_t ip);

};

#endif /* NETHEADERUTIL_H_ */
